package com.qdxwx.common.upload;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
public class UploadState implements Serializable {

    private static final long serialVersionUID = 3761560069828571039L;
    //code, errno, error 上传状态Id
    private int code;
    //上传消息
    private String msg;
    //original 原始文件路径
    private String oldPath;
    //保存文件地址
    private String savePath;
    //缩略图地址
    private String smallPath;

    private long fileSize;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getOldPath() {
        return oldPath;
    }

    public void setOldPath(String oldPath) {
        this.oldPath = oldPath;
    }

    public String getSavePath() {
        return savePath;
    }

    public void setSavePath(String savePath) {
        this.savePath = savePath;
    }

    public long getFileSize() {
        return fileSize;
    }

    public void setFileSize(long fileSize) {
        this.fileSize = fileSize;
    }

    public String getSmallPath() {
        return smallPath;
    }

    public void setSmallPath(String smallPath) {
        this.smallPath = smallPath;
    }

    public String getFileName() {
        if (this.oldPath == null) return "";
        int lastIndex = this.oldPath.lastIndexOf("\\");
        if (lastIndex < 0) {
            lastIndex = this.oldPath.lastIndexOf("/");
            if (lastIndex < 0) {
                lastIndex = 0;
            }
        }
        return this.oldPath.substring(lastIndex);
    }

    public Map<String, Object> getTinyResult() {
        Map<String, Object> map = new HashMap<>();
        map.put("code", this.code);
        map.put("location", this.savePath);
        //System.out.println("getShrinkResult");
        //System.out.println(map);
        return map;
    }

    public Map<String, Object> getResult() {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        if (this.code == 0) {
            data.put("src", this.savePath);
            data.put("oldPath", this.oldPath);
            data.put("size", this.fileSize);
            data.put("title", getFileName());
        } else {
            this.code = 1;
        }
        map.put("code", this.code);
        map.put("msg", this.msg);
        map.put("data", data);
        //System.out.println(map);
        return map;
    }
}
